# 课堂练习：
# 添加话术——》修改话术——》删除你刚新增的话术
# project_url = "http://60.205.190.66:8899"
# import requests,random
# response = requests.post(url = project_url + "/adminapi/login",json ={"account":"admin","pwd":"920509","imgcode":"0000"})
# token = response.json()['data']['token']
# random_num = random.randint(1,99999)
# response1 = requests.post(url = project_url + "/adminapi/app/wechat/speechcraft",json = {"cate_id":0,"title":"刘能的口语训练","message":"老 老 老四啊" + str(random_num),"sort":0},headers={"Authori-Zation":"Bearer "+str(token)})
# msg = response1.json()["msg"]
# assert msg == "创建话术成功"
# print(response1.text)
#
# response2 = requests.get(url = project_url + "/adminapi/app/wechat/speechcraft?page=3&limit=15&cate_id=",headers={"Authori-Zation":"Bearer "+str(token)})
# id = response2.json()['data']['list'][6]['id']
# response3 = requests.put(url=project_url + "/adminapi/app/wechat/speechcraft/"+str(id),json = {"cate_id":0,"title":"刘能的口语训练","message":"老 老 老四啊给玉田整点腰子" + str(random_num),"sort":0},headers={"Authori-Zation":"Bearer "+str(token)})
# assert response3.json()["msg"] == "修改成功"
# print(response3.json())
#
# response4 = requests.delete(project_url + "/adminapi/app/wechat/speechcraft/"+str(id),headers={"Authori-Zation":"Bearer "+str(token)})
# assert response4.json()['msg'] == "删除成功"
# print(response4.json())
# 作业：
# 1, 操作
# 业务1：登录->用户分组—>添加分组->删除分组
# 业务2：登录->客服->客服话术->添加话术->删除话术
# 业务3：登录->商品->商品分类->添加分类->删除分类
# 2、使用pytest框架做，要有setup和teardown
import pytest,requests

# from faker import Faker
list1 = []
class Test_CRMEB:
    project_url = "http://60.205.190.66:8899"
    # fake = Faker(locale='zh_cn')
    @pytest.fixture(scope='function', autouse=True)
    def login(self):
        response = requests.post(url=self.project_url + "/adminapi/login",json = {"account":"admin","pwd":"920509","imgcode":"0000"})
        self.token = response.json()['data']['token']
        yield
        print("")
    def test_add(self):
        # self.name = self.faker.name()
        response1 = requests.post(url = self.project_url + "/adminapi/user/user_group/save.html",json = {"group_name":"刘英"},headers={"Authori-Zation":"Bearer "+str(self.token)})
        assert response1.json()['msg'] == "提交成功！"
        # print(response1.json())
    def test_update(self):
        response2 = requests.get(url =self.project_url + "/adminapi/user/user_group/list?page=1&limit=15",headers={"Authori-Zation":"Bearer "+str(self.token)})
        for i in response2.json()['data']['list']:
            if i['group_name'] == "刘英":
                list1.append(i['id'])
    def test_delete(self):
        response4 = requests.delete(url=self.project_url + "/adminapi/user/user_group/del/" + str(list1[0]),headers={"Authori-Zation":"Bearer "+str(self.token)})
        assert response4.json()['msg'] == "删除成功!"
        print(response4.json())








    













